#include <bits/stdc++.h>
using namespace std;
int a[200005],b[200005],n,ans=0;
void dg(int dep)
{
	if (dep>n)
	{
		int z=0;
		for (int i=2;i<=n;i++)
		{
			for (int j=i-1;j>=1;j--)
			{
				if (b[j]==b[i])
				{
					if (a[j]==a[i]) z+=a[i];
					break;
				}
			}
		}
		ans=max(ans,z);
	}
	else 
	{
		b[dep]=1;
		dg(dep+1);
		b[dep]=0;
		dg(dep+1);
	}
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int t;
	cin>>t;
	while (t--)
	{
		cin>>n;
		for (int i=1;i<=n;i++) 
		{
			cin>>a[i];
		}
		ans=0;
		dg(1);
		cout<<ans<<endl;
	}
	return 0;
}
